package com.ruoyi.web.controller.linkage.linkageStrategy;

import com.github.pagehelper.PageHelper;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.linkage.Dto.LinkageEventDto;
import com.ruoyi.linkage.Dto.LinkageEventListDto;
import com.ruoyi.linkage.Vo.LinkageEventVo;
import com.ruoyi.linkage.domain.LinkageEvent;
import com.ruoyi.linkage.service.ILinkageEventService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * 联动事件Controller
 *
 * @author pengjie
 * @date 2023-12-20
 */
@RestController
@RequestMapping("/linkage/event")
public class LinkageEventController extends BaseController
{
    @Autowired
    private ILinkageEventService linkageEventService;

    /**
     * 查询联动事件列表
     */
    @PreAuthorize("@ss.hasPermi('linkage:event:list')")
    @GetMapping("/list")
    public TableDataInfo list(LinkageEventVo linkageEventVo)
    {
        PageHelper.startPage(Integer.parseInt(linkageEventVo.getPageNum()),Integer.parseInt(linkageEventVo.getPageSize()));
        List<LinkageEventListDto> list = linkageEventService.queryLinkageEventList(linkageEventVo);
        return getDataTable(list);
    }

    /**
     * 查询联动事件列表
     */
    @PreAuthorize("@ss.hasPermi('linkage:event:list')")
    @GetMapping("/getListCount")
    public AjaxResult getListCount()
    {
        startPage();
        LinkageEventDto dto = linkageEventService.selectLinkageEventListDto();
        List<LinkageEventDto> list =new ArrayList<>();
        list.add(dto);
        return success(list);
    }

    /**
     * 导出联动事件列表
     */
    @PreAuthorize("@ss.hasPermi('linkage:event:export')")
    @Log(title = "联动事件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LinkageEvent linkageEvent)
    {
        List<LinkageEvent> list = linkageEventService.selectLinkageEventList(linkageEvent);
        ExcelUtil<LinkageEvent> util = new ExcelUtil<LinkageEvent>(LinkageEvent.class);
        util.exportExcel(response, list, "联动事件数据");
    }

    /**
     * 获取联动事件详细信息
     */
    @PreAuthorize("@ss.hasPermi('linkage:event:query')")
    @GetMapping(value = "/{linkageEventId}")
    public AjaxResult getInfo(@PathVariable("linkageEventId") String linkageEventId)
    {
        return success(linkageEventService.selectLinkageEventByLinkageEventId(linkageEventId));
    }

    /**
     * 新增联动事件
     */
    @PreAuthorize("@ss.hasPermi('linkage:event:add')")
    @Log(title = "联动事件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LinkageEvent linkageEvent)
    {
        return toAjax(linkageEventService.insertLinkageEvent(linkageEvent));
    }

    /**
     * 修改联动事件
     */
    @PreAuthorize("@ss.hasPermi('linkage:event:edit')")
    @Log(title = "联动事件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LinkageEvent linkageEvent)
    {
        return toAjax(linkageEventService.updateLinkageEvent(linkageEvent));
    }

    /**
     * 删除联动事件
     */
    @PreAuthorize("@ss.hasPermi('linkage:event:remove')")
    @Log(title = "联动事件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{linkageEventIds}")
    public AjaxResult remove(@PathVariable String[] linkageEventIds)
    {
        return toAjax(linkageEventService.deleteLinkageEventByLinkageEventIds(linkageEventIds));
    }
}
